home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 March / Macworld CD-ROM (March 1995).cdr / Updaters / AppMaker 1.5.2->1.5.4 / Libraries / THINK / AMClassLibC / CAMPopupMenu.cp < prev    next >
Encoding:
Text File  |  1992-06-19  |  3.7 KB  |  109 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CAMPopupMenu.c
  3.  
  4.  
  5.     Used in order to provide font, size and style to popup menus.
  6.  
  7.     SUPERCLASS = CPopupMenu
  8.  
  9.     Copyright © 1991 Bowers Development Corporation. All rights reserved.
  10.  
  11.  ******************************************************************************/
  12.  
  13. #include <CBartender.h>
  14. #include <TBUtilities.h>
  15. #include <Global.h>
  16. #include "CAMPopupMenu.h"
  17.  
  18. /* used by CAMPopupMenu::IAMPopupMenu: */
  19. extern CBartender    *gBartender;
  20.  
  21. /* used by ChangeSystemFont & CAMPopupMenu::PopupSelect: */
  22. #define SysFontFamPtr    ((short *) 0x0BA6)
  23. #define SysFontSizePtr    ((short *) 0x0BA8)
  24. #define LastSpExtraPtr    ((long *) 0x0B4C)
  25.  
  26. /******************************************************************************
  27.  IAMPopupMenu
  28.  
  29.      Initialize an AppMaker popup menu.
  30.     Saves font and size in instance variables for PopupSelect,
  31.     then initializes its superclass.
  32.     Sets the DimOption so that all items in the popup will be enabled.
  33.     Since only the System Font has a checkmark symbol,
  34.     it turns off checking for all other fonts.
  35.  
  36. ******************************************************************************/
  37. void CAMPopupMenu::IAMPopupMenu        (short            aMenuID,
  38.                                      CBureaucrat    *aSupervisor,
  39.                                      Boolean        fAutoSelect,
  40.                                      Boolean        fMultiSelect,
  41.                                      short            aFontNum,
  42.                                      short            aFontSize)
  43. {
  44.     theFontNum = aFontNum;
  45.     theTextSize = aFontSize;
  46.  
  47.     CPopupMenu::IPopupMenu (aMenuID, aSupervisor, fAutoSelect, fMultiSelect);
  48.     gBartender->SetDimOption (aMenuID, dimNONE);
  49.     if (theFontNum != systemFont) {
  50.         gBartender->SetUnchecking (menuID, TRUE);
  51.                                         /* only systemFont has a check mark */
  52.     }
  53. } /* IAMPopupMenu */
  54.  
  55. /*----------*/
  56. /* This procedure changes the system font and size.
  57. */
  58. /*----------*/
  59. static void ChangeSystemFont(short fontNum, short fontSize);
  60. static void ChangeSystemFont(short fontNum, short fontSize)
  61. {
  62.     if ((*SysFontFamPtr != fontNum) || (*SysFontSizePtr != fontSize)) {
  63.         *SysFontFamPtr = fontNum;
  64.         *SysFontSizePtr = fontSize;
  65.         *LastSpExtraPtr = -1L;        /* tells Font Manager to flush & reload font cache */
  66.     } /* otherwise, *SysFontFamPtr == fontNum && *SysFontSizePtr == fontSize, do nothing */
  67. } /* ChangeSystemFont */
  68.  
  69. /******************************************************************************
  70.  PopupSelect {OVERRIDE}
  71.  
  72.      Save the port information, set font/size/style from instance variables
  73.      for this object, call inherited, then reset the port.
  74.  
  75. ******************************************************************************/
  76. long CAMPopupMenu::PopupSelect        (Point             where,
  77.                                      long            aCmd)
  78. {
  79.     short        saveSysFontFam;
  80.     short        saveSysFontSize;
  81.     long        returnedCmd;
  82.  
  83.     /* save old values of low-memory globals: */
  84.     saveSysFontFam = *SysFontFamPtr;
  85.     saveSysFontSize = *SysFontSizePtr;
  86.  
  87.     /* set the font information from instance variables: */
  88.     ChangeSystemFont(theFontNum, theTextSize);
  89.  
  90.     returnedCmd = inherited::PopupSelect (where, aCmd);
  91.  
  92.     /* set the font information back to saved variables: */
  93.     ChangeSystemFont(saveSysFontFam, saveSysFontSize);
  94.  
  95.     /* inherited::PopupSelect called InsertMenu/PopUpMenuSelect/DeleteMenu. DeleteMenu */
  96.     /* recalculated the widths of the titles in the main menu bar using the system */
  97.     /* font that we set for the pop-up, so to avoid having the user's menu bar draw */
  98.     /* strangely, we need to call DeleteMenu again here (preceded by InsertMenu) */
  99.     /* to recalculate again using the correct system font: */
  100.     if ((saveSysFontFam != theFontNum) || (saveSysFontSize != theTextSize)) {
  101.         InsertMenu (macMenu, hierMenu);    /* temporarily insert into menu list */
  102.         DeleteMenu (menuID);            /* remove from menu list (recalculates menu widths) */
  103.     }
  104.  
  105.     return (returnedCmd);
  106. } /* PopupSelect */
  107.  
  108. /* CAMPopupMenu */
  109.